package com.xxx.service;

import com.xxx.entry.Student;

import java.util.Scanner;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/7/13 13:40
 * @Copyright 博为峰
 */
public class StudentService02 {

    public Student[] stus = null;
    public Scanner scanner = null;
    public int index = 0;

    public StudentService02() {
        stus = new Student[100];
        scanner = new Scanner(System.in);
    }

    //ALT + ENTER
    public void addStu() {
        System.out.println("请输入用户名");
        Student student = new Student();
        student.setName(scanner.nextLine());
        System.out.println("请输入年龄");
        student.setAge(Integer.parseInt(scanner.nextLine()));
        System.out.println("请输入性别");
        student.setSex(scanner.nextLine());
        stus[index] = student;
        index++;
    }

    public void updateStu() {
        System.out.println("请输入要修改的用户的姓名");
        String name = scanner.nextLine();
        System.out.println("请输入要修改的用户的年龄");
        String age = scanner.nextLine();
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] != null && stus[i].getName().equals(name)) {
                stus[i].setAge(Integer.parseInt(age));
                break;
            }
        }
    }

    public void deleteStu() {
        System.out.println("请输入要删除的用户姓名");
        String name = scanner.nextLine();
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] != null && stus[i].getName().equals(name)) {
                stus[i] = null;
                break;
            }
        }
    }

    public void listStu() {
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] != null) {
                System.out.println(stus[i].getName());
            }
        }
    }

}
